//
//  MoreTableViewController.m
//  B项目
//
//  Created by lanou on 15/12/21.
//  Copyright © 2015年 tzf. All rights reserved.
//

#import "MoreTableViewController.h"
#import "SpecialModel.h"
#import "SpecialMoreTableViewCell.h"
#import "MainClassTableViewController.h"
@interface MoreTableViewController ()
@property (nonatomic, retain)NSMutableArray *SpecialArray;
@end

@implementation MoreTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setdata];
    self.tableView.rowHeight = (kWidth - 10) * 49 / 100;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.tableView registerClass:[SpecialMoreTableViewCell class] forCellReuseIdentifier:@"moreCell"];
}

- (void)setdata
{
//    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//    NSData *savedEncodedData = [defaults objectForKey:@"SpecialMoreArray"];
//    
//    if (savedEncodedData != nil) {
//        _SpecialArray = (NSMutableArray *)[NSKeyedUnarchiver unarchiveObjectWithData:savedEncodedData];
//    }else
//    {
        [LORequestManger GET:kSpecialMore success:^(id response) {
            _SpecialArray = [NSMutableArray array];
            NSDictionary *rootDic = (NSDictionary *)response;
            
            NSArray *rootArr = rootDic[@"data"][@"collections"];
            for (NSDictionary *dic in rootArr) {
                SpecialModel *model = [[SpecialModel alloc] init];
                [model setValuesForKeysWithDictionary:dic];
                [_SpecialArray addObject:model];
            }
//            NSLog(@"%@+++++++++++",_SpecialArray);
            
//            NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_SpecialArray];
//            [defaults setObject:data forKey:@"SpecialMoreArray"];
//            
            [self.tableView reloadData];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];
//    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _SpecialArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SpecialMoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"moreCell" forIndexPath:indexPath];
    cell.model = _SpecialArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    MainClassTableViewController *mainClassTVC = [[MainClassTableViewController alloc] init];
    mainClassTVC.ID = [_SpecialArray[indexPath.row] ID];
    
    [mainClassTVC setHidesBottomBarWhenPushed:YES];
    mainClassTVC.navigationItem.title = [_SpecialArray[indexPath.row] title];;
    mainClassTVC.type = @"Special";
    _myBlock(mainClassTVC);

    
}













@end
